## 3.2.2 Swaying Boat --------------- ### 3.2.2.1 Overview ![Img](./media/top1.png) Here we build a swaying boat with a Micro:bit V2 board, a servo expansion board, a 360° LEGO servo and some LEGO parts. We program to control the boat to perform some movements through the Micro:bit V2 buttons A, B and A+B. ![Img](./media/bottom1.png) --------------- ### 3.2.2.2 Materials Required ![Img](./media/A2-0.png) --------------- ### 3.2.2.3 Installation Steps ![Img](./media/2top.png) ![Img](./media/A2-1.png) ![Img](./media/A2-2.png) ![Img](./media/A2-3.png) ![Img](./media/A2-4.png) ![Img](./media/A2-5.png) ![Img](./media/A2-6.png) ![Img](./media/A2-7.png) ![Img](./media/A2-8.png) ![Img](./media/A2-9.png) ![Img](./media/A2-10.png) ![Img](./media/A2-11.png) ![Img](./media/A2-12.png) ![Img](./media/A2-13.png) ![Img](./media/A2-14.png) ![Img](./media/A2-15.png) ![Img](./media/A2-16.png) ![Img](./media/A2-17.png) ![Img](./media/A2-18.png) ![Img](./media/A2-19.png) ![Img](./media/A2-20.png) ![Img](./media/A2-21.png) ![Img](./media/A2-22.png) ![Img](./media/A02.png) ![Img](./media/wiring2.jpg) ![Img](./media/A2-23.png) ![Img](./media/A2-24.png) ![Img](./media/A2-25.png) ![Img](./media/A2-26.png) ![Img](./media/A2-27.png) ![Img](./media/A2-28.png) ![Img](./media/A2-29.png) ![Img](./media/2bottom.png) --------------- ### 3.2.2.4 Test Code ![Img](./media/couj02.png) ⚠️ **Special reminder: You can obtain the sample code through the following two methods.** #### **Method 1: drag and drop code blocks to build the sample code** **1. MakeCode programming environment** The online version of MakeCode: [MakeCode editor](https://makecode.microbit.org/#editor) **2. MakeCode extension library** ⚠️ **Special reminder: ** Copy and paste the link: `https://github.com/keyestudio2019/pxt-creative-inventors-kit-master.git` into the search box to import the library. ![Img](./media/Animation-4.gif) **3. Write the sample code** ![Img](./media/dongtu-02.gif) #### **Method 2: download the sample code file directly** **1. Download the code file** Click to download the code file: [3_3_2_Swaying_Boat](./Codes/3_3_2_Swaying_Boat.hex) **2. MakeCode programming environment** The online version of MakeCode: [MakeCode editor](https://makecode.microbit.org/#editor) **3. Load the sample code** Drag and drop the sample code to the MakeCode editor. ![Img](./media/Animation-0002.gif) ![Img](./media/line1.png) --------------- ### 3.2.2.5 Test Result ![Img](./media/4top.png) Wire up and power on through micro USB cable, and connect an external power source (four AAA-1.5V batteries installed in the battery box, ensuring sufficient power). To download the sample code using an online browser, you need to send the downloaded "**.hex**" file to the Micro:bit V2 board. There are two ways as follows: **① Download through WebUSB** For browsers like **Google Chrome / Microsoft Edge**, you need to click "**Connect Device**" to pair the device first. After that, click "**Download**" to load the sample code to the Micro:bit V2 board. ![Img](./media/Animation-02.gif) **② Download without WebUSB** For browsers like **Safari / Firefox / Other**, download and send the sample code to the Micro:bit V2 board. ![Img](./media/Animation-002.gif) After downloading the sample code, unplug the Micro USB cable to the Micro:bit V2 board. Turn the DIP switched to the RGB and ON. ![Img](./media/CBA01.png) Press button A on the Micro:bit V2 board and release it, the swaying boat glides forward, these SK6812 RGB LEDs emit red light, and the 5×5 LED matrix displays ![Img](./media/ab3.png). Press button B on the Micro:bit V2 board and release it, the swaying boat glides backward, these SK6812 RGB LEDs emit orange light, and the 5×5 LED matrix displays ![Img](./media/ab1.png). Press button A and B on the Micro:bit V2 board simultaneously and release them, the swaying boat stops, and these SK6812 RGB LEDs and the 5×5 LED matrix turn off. ![Img](./media/dongtu-002.gif) ![Img](./media/4bottom.png) ---------------